import React from 'react';
import {
  Form,
  Modal,
  Card,
  Button,
  Input
} from 'antd';
import DescriptionList from 'components/DescriptionList';
import styles from './index.less';
import moment from 'moment';
import { productType,purchaseType } from "utils/enumConfig";
import { LwjDownload } from 'components';

const { Description } = DescriptionList;
const FormItem = Form.Item
const { TextArea } = Input;
const confirmDesignModal = ({
  currentContractDetail,
  acceptDesign,
  denyDesign,
  isAcceptLoading,
  isDenyLoading,
  form: {
    getFieldDecorator,
    validateFieldsAndScroll
  },
  ...confirmDesignModalProps
}) => {

  const handleSubmit = (auditType) => {
    validateFieldsAndScroll((err, values) => {
      if (!err) {
        if (auditType === "AGREE") {
          acceptDesign(values);
        } else {
          if (_.isEmpty(values.designDeniedReason)) {
            Modal.info({ title: '提示', content: `请填写审核备注` });
            return;
          }
          values.version = currentContractDetail.version;
          denyDesign(values);
        }
      }
    });
  };

  return (
    <Modal {...confirmDesignModalProps}>
      {!_.isEmpty(currentContractDetail) && <Card bordered={false}>
        <DescriptionList
          title="设计信息"
          size="small"
          style={{ marginBottom: 32 }}>
          <Description term="合同号">{currentContractDetail.contractNum}</Description>
          <Description term="产品类型">{productType[currentContractDetail.productType]}</Description>
          <Description term="是否推送丽维家">{currentContractDetail.pushToOMSNeeded ? "是" : "否"}</Description>
          <Description term="采购方式">{purchaseType[currentContractDetail.purchaseType]}</Description>
          <Description term="合同签订时间">{moment(currentContractDetail.orderContractAt).format("YYYY-MM-DD HH:mm:ss")}</Description>
          <Description term="合同安装时间">{moment(currentContractDetail.installContractAt).format("YYYY-MM-DD HH:mm:ss")}</Description>
          {!_.isEmpty(currentContractDetail.measuredAt) &&
            <Description term="测量时间">
              {moment(currentContractDetail.measuredAt).format("YYYY-MM-DD HH:mm:ss")}
            </Description>}
          {!currentContractDetail.designNeeded && <Description term="设计师姓名">{currentContractDetail.designerUserName}</Description>}
          {!currentContractDetail.designNeeded && <Description term="设计师手机号">{currentContractDetail.designerUserPhoneNum}</Description>}
          {currentContractDetail.designNeeded && <Description term="测量时间">{moment(currentContractDetail.measuredAt).format("YYYY-MM-DD HH:mm:ss")}</Description>}
          {currentContractDetail.designNeeded && <Description term="测量设计师姓名">{currentContractDetail.measureDesignerName}</Description>}
          {currentContractDetail.designNeeded && <Description term="测量设计师手机号">{currentContractDetail.measureDesignerPhoneNum}</Description>}
          {currentContractDetail.designNeeded && <Description term="测量图纸">{<LwjDownload title={'点击下载'} targetUrl={currentContractDetail.measuredPictureAttachment} />}</Description>}
          {currentContractDetail.designNeeded && <Description term="现场图片">{<LwjDownload title={'点击下载'} targetUrl={currentContractDetail.scenePictureAttachment} />}</Description>}
          {currentContractDetail.designAttachment && <Description term="设计方案">{<LwjDownload title={'点击下载'}
                                                                                            targetUrl={currentContractDetail.designAttachment}/>}</Description>}
        </DescriptionList>
        <div className={styles.title}>备注</div>
        <Form layout="horizontal">
          <FormItem>
            {getFieldDecorator('designDeniedReason')(
              <TextArea
                style={{ minHeight: 32 }}
                placeholder="请输入备注"
                rows={4} />)}
          </FormItem>
          <FormItem
            wrapperCol={{ span: 6, offset: 19 }}>
            <Button type="primary" onClick={() => handleSubmit("AGREE")} style={{ marginRight: 10 }} loading={isAcceptLoading}>
              设计通过
            </Button>
            <Button type="primary" onClick={() => handleSubmit("DISAGREE")} loading={isDenyLoading}>
              设计不通过
            </Button>
          </FormItem>
        </Form>
      </Card>}
    </Modal>
  )
}

export default Form.create()(confirmDesignModal);
